
//查询机构视频课程内容详情页面

exports.searchVideoDetail = function(req,res) {
//平台通知列表
    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;
    var ov_id = restfulParams.ov_id;    //课程主键id
    var ov_coupon_id = 0
    var ov_coupon_type = 0

    var ov_skin_id = 0;  //皮肤id
    var ov_course_type = 0;  //视频课类型
    //最终结果
    var resultData = {};

    //任务流创建
    async.waterfall([
        //获取视频的基本信息
        function(cb){
            R.SEND_HTTP(
                req,
                {
                    url    : CORE_APIConfig.coreAPI.searchOrganizationVideo+"/ov_id/"+ov_id  ,
                    method : 'GET',
                },
                function (err, data) {
                    if (err) {
                        return cb(err, data);
                    }
                    ov_skin_id = data.data[0].ov_skin_id;
                    ov_course_type = data.data[0].ov_course_type;
                    ov_coupon_id = data.data[0].ov_coupon_id;
                    ov_coupon_type = data.data[0].ov_coupon_type;
                    resultData.VideoDetail = data.data[0];
                    cb();
                }
            );
        },
        //查询他对应的皮肤
        function(cb){
            R.SEND_HTTP(
                req,
                {
                    url    : CORE_APIConfig.coreAPI.searchActivitySkin+"/as_id/"+ov_skin_id  ,
                    method : 'GET',
                },
                function (err, data) {
                    if (err) {
                        return cb(err, data);
                    }
                    resultData.skinData = data.data[0];
                    cb();
                }
            );

        },
        //查询内容
        function(cb){
            R.SEND_HTTP(
                req,
                {
                    url    : CORE_APIConfig.coreAPI.searchOrganizationVideoContent+"/ovc_ovid/"+ov_id  ,
                    method : 'GET',
                },
                function (err, data) {
                    if (err) {
                        return cb(err, data);
                    }
                    resultData.VideoContentData = data.data;
                    cb();
                }
            );
        },
        //查询赠券的名字
        function(cb){
            console.log(ov_coupon_type);
            console.log(ov_coupon_id);
            if(ov_coupon_type == 0 && ov_coupon_id != 0){//代金劵
                console.log(CORE_APIConfig.coreAPI.search_cash_coupon+"/cc_id/"+ov_coupon_id )
                R.SEND_HTTP(
                    req,
                    {
                        url    : CORE_APIConfig.coreAPI.search_cash_coupon+"/is_all/1/cc_id/"+ov_coupon_id,
                        method : 'POST',
                        data:{
                            fields:["cc_name"].join(",")
                        }
                    },
                    function (err, data) {
                        if (err) {
                            return cb(err, data);
                        }
                        console.log(data);
                        resultData.couponName = data.data[0].cc_name;
                        cb();
                    }
                );

            }else if(ov_coupon_type == 1  && ov_coupon_id != 0){//约课券
                R.SEND_HTTP(
                    req,
                    {
                        url    : CORE_APIConfig.coreAPI.searchCourseCoupon+"/cc_id/"+ov_coupon_id  ,
                        method : 'POST',
                        data:{
                            fields:["cc_name"].join(",")
                        }
                    },
                    function (err, data) {
                        if (err) {
                            return cb(err, data);
                        }
                        resultData.couponName = data.data[0].cc_name;
                        cb();
                    }
                );
            }else if(ov_coupon_type == 2  && ov_coupon_id != 0){//兑换券
                R.SEND_HTTP(
                    req,
                    {
                        url    : CORE_APIConfig.coreAPI.searchExchangeCoupon+"/is_all/1/ec_id/"+ov_coupon_id  ,
                        method : 'POST',
                        data:{
                            fields:["ec_name"].join(",")
                        }
                    },
                    function (err, data) {
                        if (err) {
                            return cb(err, data);
                        }
                        resultData.couponName = data.data[0].ec_name;
                        cb();
                    }
                );
            }else{
                resultData.couponName = "";
                cb()
            }

        }



    ],function(err, result){

        //返回最终拼接结果
        RES.response(res,true,resultData);

    });

}